<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>酷睿后台</title>
	<style>
		*{
			margin: 0;
			padding: 0;
			list-style: none;
			text-decoration: none;
		}
		#container{
			width: 100%;
			height: 2000px;
		}
		#top{
			width: 100%;
			height: 35px;
			background: #393f77;
			border-bottom: 0.1px solid #666;
		}
		#title{
			color: #c1d5ec;
			cursor: pointer;
			font-family: "Microsoft YaHei";
			margin-left: 20px;
			font-size: 18px;
			line-height: 36px;
		}
		#title:hover{
			text-decoration: underline;
		}
		#welcome{
			color: #c1d5ec;
			position: absolute;
			right: 50px;
			padding: 15px 20px 0 0;
			font-family: tahoma,arial,"SimSun","Helvetica Neue",Helvetica,sans-serif;
			font-size: 15px;
			line-height: 18px;
		}
		#quit{
			color: #c1d5ec;
			padding: 15px 16px 0 0;
			text-decoration: none;
			font-family: tahoma,arial,"SimSun","Helvetica Neue",Helvetica,sans-serif;
			font-size: 13px;
			line-height: 18px;
			float: right;
			cursor: pointer;
		}
		#quit:hover{
			color: #f60;
			text-decoration: underline;
		}
		#middle{
			width: 100%;
			height: 100%;
			display: flex;
		}
		#middle > #left{
			width: 16%;
			height: 100%;	
			background: #e8e9ee;
		}
		#left > ul{
			padding-top: 15px;
		}
		#left > ul > li{
			width: 100%;
			height: 30px;
			margin-top: 10px;
			text-align: center;
			line-height: 30px;
		}
		#left > ul > li > a{
			color: #5c637b;
		}
		#left > ul > li > a:hover{
			color: #f60;
			text-decoration: underline;
		}
		#middle > #right{
			width: 87%;
		}
		coder{
			display: none;
		}
		p{
			text-indent:2em;
			width: 600px;
		}
		.input{
			border: 1.5px solid #87CEFA;
			border-radius: 2px; 
			width: 160px;
			height:20px;
			line-height: 20px;
			margin:0px 0px 10px 0px;
		}
		.input2{
			text-decoration:none;  
    		background:#2f435e;  
    		color:#fff;       
    		padding: 5px 15px 5px 15px;  
    		font-size:10px;     		  
    		font-weight:bold;  
    		border-radius:3px;           		
		}
		.input2:hover{ 
			background:#385f9e;
			cursor: pointer;
			 }
/*		.comment{
			border: 1.5px solid #87CEFA;
			border-radius: 2px; 
			width: 500px;
		}*/
		.comment{
			top: 20px;
    		width: 100%;
    		margin: 0 auto;
    		border-top: 3px solid #F2F2F2;
    		padding: 10px;
    		padding-left: 100px;
    		padding-top: 20px;
		}
	</style>
</head>
<body>
	<div id="container">
		<div id="top">
			<!-- <span id="title">酷睿影评·后台管理</span>
			<span id="welcome">Welcome,Bruce</span>
			<a href="admin.html" title="退出系统" id="quit">[退出]</a> -->
		</div>
		<div id="middle">
			<div id="left">
				<ul>
					<li><a id="firstPage" href="javascript:setRight('last_comments')">最新评论</a></li>
					<li><a href="javascript:setRight('select_comments')">查找评论</a></li>
					<li><a href="javascript:setRight('delete_comments')">删除评论</a></li>
					<li><a href="javascript:setRight('select_movies')">查找影片</a></li>
					<li><a href="javascript:setRight('add_movie')">添加影片</a></li>
					<li><a href="javascript:setRight('modify_movie')">修改影片</a></li>
					<li><a href="javascript:setRight('delet_movie')">删除影片</a></li>
					<li><a href="javascript:setRight('select_user')">查找用户</a></li>
					<li><a href="javascript:setRight('lock_user')">封禁用户</a></li>
					<li><a href="javascript:setRight('unlock_user')">解除封禁</a></li>
					<li><a href="javascript:setRight('add_ad')">添加推广</a></li>
				</ul>
			</div>

			<div id="right">
				
			</div>
		</div>
	</div>

	<coder id="last_comments">
		
	</coder>

	<coder id="select_comments">
		<h1>查找指定用户发表的评论</h1><br>
		<form action="" id="select_comments_form">
			<label for="username">用户名：</label>
			<input type="text" name="username" class="input">
			<input type="button" onclick="findComment('select_comments_form')" value="查找" class="input2"><br><br>
		</form>
		<div id="select_comment">
			
		</div>
	</coder>

	<coder id="delete_comments">
		<h1>根据评论ID删除评论</h1><br>
		<form action="" id="delete_comments_form">
			<label for="comment_id">评论ID：</label>
			<input type="text" name="comment_id" class="input">
			<input type="button" onclick="deleteComment('delete_comments_form')" value="确定" class="input2"><br><br>
		</form>
		<div id="delete_comment">
			
		</div>
	</coder>

	<coder id="select_movies">
		<h1>输入影片名查找电影</h1><br>
		<form action="" id="select_movies_form">
			<div class="item">
				<label for="movie_name">电影名：</label>
				<input type="text" name="movie_name" class="input">
				<input type="button" onclick="findMovie('select_movies_form')" value="确认" class="input2"><br><br>
			</div>
		</form>
		<div id="select_movie">
			
		</div>
	</coder>

	<coder id="add_movie">
		<h1>添加电影</h1><br>
		<form action="" id="add_movie_form">
			<div class="item">
				<label for="movie_name">片&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
				<input type="text" name="movie_name" class="input">
			</div>
			<div class="item">
				<label for="movie_director">导&nbsp;&nbsp;&nbsp;&nbsp;演：</label>
				<input type="text" name="movie_director" class="input">
			</div>
			<div class="item">
				<label for="movie_writer">编&nbsp;&nbsp;&nbsp;&nbsp;剧：</label>
				<input type="text" name="movie_writer" class="input">
			</div>
			<div class="item">
				<label for="movie_actor">主&nbsp;&nbsp;&nbsp;&nbsp;演：</label>
				<input type="text" name="movie_actor" class="input">
			</div>
			<div class="item">
				<label for="movie_type">类&nbsp;&nbsp;&nbsp;&nbsp;型：</label>
				<input type="text" name="movie_type" class="input">
			</div>
			<div class="item">
				<label for="movie_region">地&nbsp;&nbsp;&nbsp;&nbsp;区：</label>
				<input type="text" name="movie_region" class="input">
			</div>
			<div class="item">
				<label for="movie_lang">语&nbsp;&nbsp;&nbsp;&nbsp;言：</label>
				<input type="text" name="movie_lang" class="input">
			</div>
			<div class="item">
				<label for="movie_date">首&nbsp;&nbsp;&nbsp;&nbsp;映：</label>
				<input type="date" name="movie_date" class="input">
			</div>
			<div class="item">
				<label for="movie_length">片&nbsp;&nbsp;&nbsp;&nbsp;长：</label>
				<input type="text" name="movie_length" class="input">
			</div>
			<div class="item">
				<label for="movie_alias">别&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
				<input type="text" name="movie_alias" class="input">
			</div>
			<div class="item">
				<label for="movie_juqing">简&nbsp;&nbsp;&nbsp;&nbsp;介：</label>
				<input type="text" name="movie_juqing" class="input">
			</div>
			<div class="item">
				<label for="movie_cover">封&nbsp;&nbsp;&nbsp;&nbsp;面：</label>
				<input type="text" name="movie_cover" class="input">
			</div>
			<div class="item">
				<label for="jishu">集&nbsp;&nbsp;&nbsp;&nbsp;数：</label>
				<input type="text" name="jishu" class="input">
			</div>
			<input type="button" onclick="addMovie('add_movie_form')" value="确认添加" class="input2" style="margin-left: 83px;
    margin-top: 15px;">
		</form>
	</coder>

	<coder id="modify_movie">
		<h1>输入影片ID修改影片信息</h1><br>
		<form action="" id="modify_movie_form">
			<div class="item">
				<label for="movie_id">影片ID：</label>
				<input type="text" name="movie_id" class="input">
			</div>
			<div class="item">
				<span>字段名：</span>
				<select name="field">
					<option value="movie_name">片&nbsp;&nbsp;名</option>
					<option value="movie_director">导&nbsp;&nbsp;演</option>
					<option value="movie_writer">编&nbsp;&nbsp;剧</option>
					<option value="movie_actor">主&nbsp;&nbsp;演</option>
					<option value="movie_type">类&nbsp;&nbsp;型</option>
					<option value="movie_region">地&nbsp;&nbsp;区</option>
					<option value="movie_lang">语&nbsp;&nbsp;言</option>
					<option value="movie_date">首&nbsp;&nbsp;映</option>
					<option value="movie_length">片&nbsp;&nbsp;长</option>
					<option value="movie_alias">别&nbsp;&nbsp;名</option>
					<option value="movie_juqing">简&nbsp;&nbsp;介</option>
					<option value="movie_cover">封&nbsp;&nbsp;面</option>
					<option value="jishu">集&nbsp;&nbsp;数</option>
				</select>
				<label for="modify">修改值：</label>
				<input type="text" name="modify" placeholder="首映日期格式:XXXX-XX-XX" class="input">
			</div>
			<input type="button" onclick="modifyMovie('modify_movie_form')" value="确认修改" class="input2" style="margin-left: 70px;
    margin-top: 15px;">
		</form>
		<div id="modifyMovieInfo">
			
		</div>
	</coder>

	<coder id="delet_movie">
		<h1>输入影片ID删除影片</h1><br>
		<form action="" id="delet_movie_form">
			<div class="item">
				<label for="movie_id">影片ID：</label>
				<input type="text" name="movie_id" class="input">
				<input type="button" onclick="deleteMovie('delet_movie_form')" value="确认删除" class="input2"><br><br>
			</div>
		</form>
		<div id="deletInfo">
			
		</div>
	</coder>

	<coder id="select_user">
		<h1>根据用户名查找用户</h1><br>
		<form action="" id="select_user_form">
			<div class="item">
				<label for="user_name">用户名：</label>
				<input type="text" name="user_name" class="input">
				<input type="button" onclick="findUser('select_user_form')" value="确认" class="input2"><br>
			</div>
		</form>
		<div id="select_userInfo">
			
		</div>
	</coder>

	<coder id="lock_user">
		<h1>根据用户ID封禁用户</h1><br>
		<form action="" id="lock_user_form">
			<div class="item">
				<label for="user_id">用户ID：</label>
				<input type="text" name="user_id" class="input">
				<input type="button" onclick="lockUser('lock_user_form')" value="确认" class="input2"><br><br>
			</div>
		</form>
	</coder>

	<coder id="unlock_user">
		<h1>根据用户ID解封用户</h1><br>
		<form action="" id="unlock_user_form">
			<div class="item">
				<label for="user_id">用户ID：</label>
				<input type="text" name="user_id" class="input">
				<input type="button" onclick="unlockUser('unlock_user_form')" value="确认" class="input2"><br><br>
			</div>
		</form>
		<div id="unlockUserInfo">
			
		</div>
	</coder>

	<coder id="add_ad">
		<h1>添加推广</h1><br>
		<form action="" id="add_ad_form">
			<div class="item">
				<label for="ad_name">推广名称：</label>
				<input type="text" name="ad_name" class="input">
			</div>
			<div class="item">
				<label for="ad_path">推广链接：</label>
				<input type="text" name="ad_path" class="input">
			</div>
			<div class="item">
				<label for="ad_money">推广报酬：</label>
				<input type="text" name="ad_money" class="input">
			</div>
			<div class="item">
				<label for="ad_picture">推广图片：</label>
				<input type="text" name="ad_picture" class="input">
			</div>
			<input type="button" onclick="addAdvertising('add_ad_form')" value="确认添加" class="input2" style="margin-left: 83px;
    margin-top: 15px;"><br><br>
		</form>
		<div id="addAdInfo">
			
		</div>
	</coder>

	<!-- 查找评论根据时间倒叙的ejs模板 -->
	<script src="ejs.min.js"></script>
	<script id="temp4LastComment" type="text/template">
		<h1>最新评论</h1><br>
		<%  console.log(last_comment);
		for(var i=0;i<last_comment.userInfo.length;i++) {%>
			<div class="comment">
				<span style="color:#666;">评论ID：<%=last_comment.commentInfo[i].comment_id%></span><br>
				<span style="color:skyblue;"><%=last_comment.userInfo[i].user_name%></span>
				<span>&nbsp;评论&nbsp;</span>
				<span style="color:#555;">《<%=last_comment.movieInfo[i].movie_name%>》</span>
				<span>&nbsp;&nbsp;</span>
				<span style="color:#aaa;"><%=: last_comment.commentInfo[i].comment_time | time%></span><br><br>
				<p><span><%= last_comment.commentInfo[i].comment_content%></span></p>
			</div><br>
		<%  }  %>
	</script>
	<script>
		// 最新评论
		var data = sessionStorage.getItem('currentUser');
		if(data){
			data=JSON.parse(data);
		}
		if(!data)
			data={user_name:""};
		if(data.user_name != ""){
			var data = null;
			fetch('/CoolReal/lastcomment').then(function(res) {
				return res.json();
			}).then(function(data) {
				if (!data) {
					return;
				}
				ejs.filters.time = function(d){
					var date = new Date(d);
					if (date instanceof Date) {
						return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
					}
				}
				var temp4LastComment = document.getElementById('temp4LastComment');
				var html = ejs.render(temp4LastComment.innerHTML, {last_comment: data});
				var last_comments = document.getElementById('last_comments');
				last_comments.innerHTML = html;
				setRight('last_comments');
			});
		}
	</script>

	<!-- 根据用户名查找评论的ejs模板 -->
	<script id="temp4FindComment" type="text/template">
			<%  console.log(find_comment);
			if(find_comment.userInfo.length>0){
				for(var i=0;i<find_comment.userInfo.length;i++) {%>
					<div class="comment">
						<span style="color:#666;">评论ID：<%=find_comment.commentInfo[i].comment_id%></span><br>
						<span style="color:skyblue;"><%=find_comment.userInfo[i].user_name%></span>
						<span>&nbsp;评论&nbsp;</span>
						<span style="color:#555;">《<%=find_comment.movieInfo[i].movie_name%>》</span>
						<span>&nbsp;&nbsp;</span>
						<span style="color:#aaa;"><%=: find_comment.commentInfo[i].comment_time | time%></span><br><br>
						<p><span><%= find_comment.commentInfo[i].comment_content%></span></p>
					</div><br>
				<%  }
			}else{  %>
				<h1>未找到相关评论！</h1>
			<%  }  %>
	</script>
	<script>
		//根据用户名查找评论
		function findComment(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/selectcomments',{
				 credentials: 'include',
				method: 'POST',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if (!data) {
					return;
				}
				ejs.filters.time = function(d){
					var date = new Date(d);
					if (date instanceof Date) {
						return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
					}
				}
				var temp4FindComment = document.getElementById('temp4FindComment');
				var html = ejs.render(temp4FindComment.innerHTML, {find_comment: data});
				var select_comment = document.getElementById('select_comment');
				select_comment.innerHTML = html;
			});
		}
	</script>

	<script>
		//根据ID删除评论
		function deleteComment(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/deletecomment',{
				 credentials: 'include',
				method: 'POST',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if(data == 1){
					alert("删除成功！");
				}else if(data == -1){
					alert("删除失败！请输入正确的评论ID！");
				}else{
					alert("未知错误！请检查输入内容！");
				}
				if (!data) {
					return;
				}
			});
		}
	</script>

	<!-- 查找影片的ejs模板 -->
	<script id="temp4FindMovie" type="text/template">
			<%  console.log(find_movie);
			for(var i in find_movie) {%>
				<div class="movie">
					<img src="<%=find_movie[i].movie_cover%>" alt=""><br>
					<span>ID：</span><span><%=find_movie[i].movie_id%></span><br>
					<span>片名：</span><span><%=find_movie[i].movie_name%></span><br>
					<span>导演：</span><span><%=find_movie[i].movie_director%></span><br>
					<span>编剧：</span><span><%=find_movie[i].movie_writer%></span><br>
					<span>主演：</span><span><%=find_movie[i].movie_actor%></span><br>
					<span>类型：</span><span><%=find_movie[i].movie_type%></span><br>
					<span>地区：</span><span><%=find_movie[i].movie_region%></span><br>
					<span>语言：</span><span><%=find_movie[i].movie_lang%></span><br>
					<span>上映日期：</span><span><%=: find_movie[i].movie_date | time%></span><br>
					<span>片长：</span><span><%=find_movie[i].movie_length%></span><br>
					<span>别名：</span><span><%=find_movie[i].movie_alias%></span><br>
					<span>剧情简介：</span><p><%=find_movie[i].movie_juqing%></p><br>
					<span>封面地址：</span><span><%=find_movie[i].movie_cover%></span><br>
					<span>集数：</span><span><%=find_movie[i].jishu%></span><br><br>
				</div><br><br>
			<%  }  %>
	</script>
	<script>
		//根据片名查找影片详情
		function findMovie(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/moviebyname',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if (!data) {
					return;
				}
				ejs.filters.time = function(d){
					var date = new Date(d);
					if (date instanceof Date) {
						return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`;
					}
				}
				var temp4FindMovie = document.getElementById('temp4FindMovie');
				var html = ejs.render(temp4FindMovie.innerHTML, {find_movie: data});
				var select_movie = document.getElementById('select_movie');
				select_movie.innerHTML = html;
			});
		}
	</script>

	<!-- 添加影片的ejs模板 -->
<!-- 	<script id="temp4AddMovie" type="text/template">
			<%  console.log(addInfo);
			if(addInfo == 1){
				alert("添加成功！");
			}else if(addInfo == -1){
				alert("添加失败！该影片已存在！");
			}else if(addInfo == 0){
				alert("未知错误！请检查输入内容！");
			}  %>
	</script> -->
	<script>
		//添加影片
		function addMovie(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/add_movie',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if(data == 1){
					alert("添加成功！");
				}else if(data == -1){
					alert("添加失败！该影片已存在！");
				}else if(data == -2){
					alert("添加失败！请填写正确的首映日期！");
				}else{
					alert("未知错误！请检查输入内容！");
				}
				if (!data) {
					return;
				}
				// var temp4AddMovie = document.getElementById('temp4AddMovie');
				// var html = ejs.render(temp4AddMovie.innerHTML, {addInfo: data});
				// var add_movie = document.getElementById('add_movie');
				// add_movie.innerHTML = html;
			});
		}
	</script>

	<script>
		//修改影片信息
		function modifyMovie(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/modify_movie',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if(data == 1){
					alert("修改成功！");
				}else if(data == -1){
					alert("修改失败！请输入正确的影片ID！");
				}else{
					alert("未知错误！请检查输入内容！");
				}
				if (!data) {
					return;
				}
			});
		}
	</script>

	<script>
		//根据ID删除影片
		function deleteMovie(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/delete',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if(data == 1){
					alert("删除成功！");
				}else if(data == -1){
					alert("删除失败！请输入正确的影片ID！");
				}else{
					alert("未知错误！请检查输入内容！");
				}
				if (!data) {
					return;
				}
			});
		}
	</script>

	<!-- 根据用户名查找用户信息的ejs模板 -->
	<script id="temp4FindUser" type="text/template">
			<%  console.log(userInfo);
			for(var i in userInfo) {%>
				<br>
				<span>用&nbsp;户&nbsp;ID：</span>
				<span><%=userInfo[i].user_id%></span><br>
				<span>用&nbsp;户&nbsp;名：</span>
				<span><%=userInfo[i].user_name%></span><br>
				<span>手机号码：</span>
				<span><%=userInfo[i].user_phone%></span><br>
				<span>所在地址：</span>
				<span><%=userInfo[i].user_addr%></span><br>
				<span>邮箱地址：</span>
				<span><%=userInfo[i].user_mail%></span><br>
				<span>用户权限：</span>
				<%if(userInfo[i].quanxian == 0) {%>
					<span>管理员</span><br>
				<%}else {%>
					<span>普通用户</span><br>
				<%}%>
				<span>是否封禁：</span>
				<%if(userInfo[i].user_enable == 0) {%>
					<span>已被封号</span><br>
				<%}else {%>
					<span>未封号</span><br>
				<%}%>
			<%  }  %>
	</script>
	<script>
		//根据用户名查找用户信息
		function findUser(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/find_user',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if (!data) {
					return;
				}
				var temp4FindUser = document.getElementById('temp4FindUser');
				var html = ejs.render(temp4FindUser.innerHTML, {userInfo: data});
				var select_userInfo = document.getElementById('select_userInfo');
				select_userInfo.innerHTML = html;
			});
		}
	</script>

	<script>
		//封禁用户
		function lockUser(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/lock',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if(data == 1){
					alert("该用户已被封号！");
				}else if(data == -1) {
					alert("你封你自己干啥？");
				}else {
					alert("封号失败！未找到该用户！");
				}
				if (!data) {
					return;
				}
			});
		}
	</script>

	<script>
		//解封用户
		function unlockUser(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/unlock',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if(data == 1){
					alert("该用户已被解封！");
				}else{
					alert("解封失败！未找到该用户！");
				}
				if (!data) {
					return;
				}
			});
		}
	</script>

	<script>
		//添加广告
		function addAdvertising(id){
			var fom = document.getElementById(id);
			var formData = new FormData(fom);
			var data = null;
			fetch('/CoolReal/addad',{
				method: 'POST',
				 credentials: 'include',
 				body: encodeURI(Array.from(formData.entries()).map(el=>el.join('=')).join('&')),
 				headers:{
					"Content-type":"application/x-www-form-urlencoded;charset=utf-8"
				}
			}).then(function(res) {
				return res.json();
			}).then(function(data) {
				if(data == 1){
					alert("添加成功！");
				}else if(data == -1){
					alert("添加失败！该推广已经存在！");
				}else{
					alert("添加失败！请检查输入内容！");
				}
				if (!data) {
					return;
				}
			});
		}
	</script>

	<script id="temp4Welcome" type="text/template">
		<span id="title">酷睿影评·后台管理</span>
		<span id="welcome">Welcome,&nbsp;<%=user_name%></span>
		<a href="javascript:quit();" title="退出系统" id="quit">[退出]</a>
	</script>
	<script>
		var temp4Welcome = document.getElementById('temp4Welcome');
		var data = sessionStorage.getItem('currentUser');
		if(data){
			data=JSON.parse(data);
		}
		if(!data)
			data={user_name:""}
		var html = ejs.render(temp4Welcome.innerHTML,data);
		var toptitle = document.getElementById('top');
		toptitle.innerHTML = html;
	</script>

	<script>
		function quit(){
			sessionStorage.clear();
			window.location.href="admin_login.html";
		}

		function setRight(id){
			var source = document.getElementById(id);
			var target = document.getElementById('right');
			target.innerHTML = source.innerHTML;
		}

		window.addEventListener('load',function(){

			if(data.user_name == ""){
				alert("请先登录！");
				window.location.href="admin_login.html";
			}
		});
		
	</script>
</body>
</html>